package cn.edu.zhku.citrusmonitor.person.admin.dao;

import java.sql.SQLException;

import org.apache.commons.dbutils.BasicRowProcessor;
import org.apache.commons.dbutils.BeanProcessor;
import org.apache.commons.dbutils.GenerousBeanProcessor;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.RowProcessor;
import org.apache.commons.dbutils.handlers.BeanHandler;

import cn.edu.zhku.citrusmonitor.domain.TbAdmin;
import cn.edu.zhku.citrusmonitor.util.C3P0Util;

public class AdminDaoImpl implements AdminDao {
	BeanProcessor bean=new GenerousBeanProcessor();
	RowProcessor processor=new BasicRowProcessor(bean);
	@Override
	public TbAdmin getAdminByAccount(String adminAccount) throws SQLException {
		// TODO Auto-generated method stub
		QueryRunner qr=new QueryRunner(C3P0Util.getDataSource());
		return qr.query("select * from admin where admin_account=?", new BeanHandler<TbAdmin>(TbAdmin.class,processor),adminAccount);
	}

	@Override
	public TbAdmin getAdminByAccountAndPsw(String adminAccount, String password) throws SQLException {
		// TODO Auto-generated method stub
		QueryRunner qr=new QueryRunner(C3P0Util.getDataSource());
		return qr.query("select * from admin where admin_account=? and password=?", new BeanHandler<TbAdmin>(TbAdmin.class,processor),adminAccount,password);
	}

}
